<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数据详情 - 河域分割系统</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/main.css') }}">
</head>
<body>
    <!-- 导航栏 -->
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <div class="container">
            <a class="navbar-brand" href="{{ url_for('index') }}">河域分割系统</a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('index') }}">首页</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('dashboard') }}">仪表板</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link active" href="{{ url_for('data.my_data') }}">我的数据</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('data.upload') }}">上传数据</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" href="{{ url_for('analysis.time_series_analysis') }}">时间分析</a>
                    </li>
                </ul>
                <ul class="navbar-nav">
                    <li class="nav-item dropdown">
                        <a class="nav-link dropdown-toggle" href="#" id="userDropdown" role="button" data-bs-toggle="dropdown">
                            <i class="bi bi-person-circle"></i> {{ current_user.username }}
                        </a>
                        <ul class="dropdown-menu dropdown-menu-end">
                            <li><a class="dropdown-item" href="#">个人资料</a></li>
                            <li><a class="dropdown-item" href="#">设置</a></li>
                            <li><hr class="dropdown-divider"></li>
                            <li><a class="dropdown-item" href="{{ url_for('auth.logout') }}">退出登录</a></li>
                        </ul>
                    </li>
                </ul>
            </div>
        </div>
    </nav>

    <!-- 主内容 -->
    <div class="container my-4">
        <div class="row mb-4">
            <div class="col-md-8">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="{{ url_for('data.my_data') }}">我的数据</a></li>
                        <li class="breadcrumb-item active">{{ image.filename.split('_', 1)[1] }}</li>
                    </ol>
                </nav>
                <h2>{{ image.filename.split('_', 1)[1] }}</h2>
                <p class="text-muted">上传于: {{ image.upload_date.strftime('%Y-%m-%d %H:%M') }}</p>
            </div>
            <div class="col-md-4 text-end d-flex align-items-center justify-content-end">
                <button class="btn btn-outline-danger me-2 delete-image" data-image-id="{{ image.id }}">
                    <i class="bi bi-trash"></i> 删除数据
                </button>
                <a href="{{ url_for('data.my_data') }}" class="btn btn-outline-secondary">
                    <i class="bi bi-arrow-left"></i> 返回列表
                </a>
            </div>
        </div>

        <!-- 数据信息卡片 -->
        <div class="row mb-4">
            <div class="col-md-4 mb-4">
                <div class="card h-100">
                    <div class="card-header">
                        <h5 class="mb-0">数据信息</h5>
                    </div>
                    <div class="card-body">
                        <div class="mb-3">
                            <strong>文件名:</strong>
                            <p class="text-break">{{ image.filename.split('_', 1)[1] }}</p>
                        </div>
                        <div class="mb-3">
                            <strong>类型:</strong>
                            <p>
                                {% if image.image_type == 'satellite' %}
                                <span class="badge bg-primary">卫星影像</span>
                                {% else %}
                                <span class="badge bg-success">SHP文件</span>
                                {% endif %}
                            </p>
                        </div>
                        {% if image.city %}
                        <div class="mb-3">
                            <strong>城市:</strong>
                            <p>{{ image.city }}</p>
                        </div>
                        {% endif %}
                        {% if image.latitude and image.longitude %}
                        <div class="mb-3">
                            <strong>坐标:</strong>
                            <p>{{ image.latitude }}, {{ image.longitude }}</p>
                        </div>
                        {% endif %}
                        
                        <!-- 添加编辑位置信息按钮 -->
                        <div class="d-grid gap-2">
                            <a href="{{ url_for('data.edit_location', image_id=image.id) }}" class="btn btn-outline-primary">
                                <i class="bi bi-geo-alt"></i> 编辑位置信息
                            </a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-md-8 mb-4">
                <div class="card h-100">
                    <div class="card-header d-flex justify-content-between align-items-center">
                        <h5 class="mb-0">预览</h5>
                        <a href="/uploads/{{ image.filename }}" class="btn btn-sm btn-outline-primary" download>
                            <i class="bi bi-download"></i> 下载原始文件
                        </a>
                    </div>
                    <div class="card-body text-center">
                        {% if image.image_type == 'satellite' %}
                            <img src="/uploads/{{ image.filename }}" class="img-fluid preview-image" 
                                 alt="预览图像" style="max-height: 300px;">
                        {% else %}
                            <div class="alert alert-info">
                                SHP文件无法直接预览，请使用GIS工具打开
                            </div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>

        <!-- 模型预测 -->
        <div class="row mb-4">
            <div class="col-12">
                <div class="card">
                    <div class="card-header d-flex justify-content-between align-items-center">
                        <h5 class="mb-0">模型预测</h5>
                        {% if prediction_available %}
                        <div>
                            <a href="{{ url_for('prediction.select_model', image_id=image.id) }}" class="btn btn-sm btn-primary">
                                <i class="bi bi-lightning"></i> 开始新预测
                            </a>
                        </div>
                        {% else %}
                        <div>
                            <span class="badge bg-warning">预测功能暂不可用</span>
                        </div>
                        {% endif %}
                    </div>
                    <div class="card-body">
                        {% if image.predictions %}
                            <div class="table-responsive">
                                <table class="table table-hover">
                                    <thead>
                                        <tr>
                                            <th>预测日期</th>
                                            <th>模型</th>
                                            <th>水域占比</th>
                                            <th>操作</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        {% for prediction in image.predictions %}
                                        <tr>
                                            <td>{{ prediction.prediction_date.strftime('%Y-%m-%d %H:%M') }}</td>
                                            <td>{{ prediction.model_name }}</td>
                                            <td>{{ prediction.water_percentage }}%</td>
                                            <td>
                                                {% if prediction_available %}
                                                <a href="{{ url_for('prediction.view_result', prediction_id=prediction.id) }}" class="btn btn-sm btn-outline-primary">
                                                    <i class="bi bi-eye"></i> 查看
                                                </a>
                                                {% else %}
                                                <button class="btn btn-sm btn-outline-secondary" disabled>
                                                    <i class="bi bi-eye"></i> 查看
                                                </button>
                                                {% endif %}
                                            </td>
                                        </tr>
                                        {% endfor %}
                                    </tbody>
                                </table>
                            </div>
                        {% else %}
                            <div class="alert alert-info">
                                <p class="mb-0 text-center">
                                    尚未对此数据进行预测。
                                    {% if prediction_available %}
                                    <a href="{{ url_for('prediction.select_model', image_id=image.id) }}">立即开始预测</a>
                                    {% else %}
                                    <span class="text-muted">预测功能暂不可用 (缺少PyTorch依赖)</span>
                                    {% endif %}
                                </p>
                            </div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 删除确认模态框 -->
    <div class="modal fade" id="deleteModal" tabindex="-1" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">确认删除</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <p>确定要删除这个数据吗？此操作不可撤销，并且会删除与此数据相关的所有预测和分析结果。</p>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-danger" id="confirmDelete">确认删除</button>
                </div>
            </div>
        </div>
    </div>

    <!-- 页脚 -->
    <footer class="bg-dark text-white py-4 mt-5">
        <div class="container">
            <div class="row">
                <div class="col-md-6">
                    <h5>河域分割系统</h5>
                    <p>基于深度学习的河域分割与分析平台</p>
                </div>
                <div class="col-md-3">
                    <h5>链接</h5>
                    <ul class="list-unstyled">
                        <li><a href="{{ url_for('index') }}" class="text-white">首页</a></li>
                        <li><a href="{{ url_for('dashboard') }}" class="text-white">仪表板</a></li>
                        <li><a href="{{ url_for('data.my_data') }}" class="text-white">我的数据</a></li>
                    </ul>
                </div>
                <div class="col-md-3">
                    <h5>账户</h5>
                    <ul class="list-unstyled">
                        <li><a href="#" class="text-white">个人资料</a></li>
                        <li><a href="#" class="text-white">设置</a></li>
                        <li><a href="{{ url_for('auth.logout') }}" class="text-white">退出登录</a></li>
                    </ul>
                </div>
            </div>
            <hr>
            <div class="text-center">
                <p>&copy; 2023 河域分割系统. 保留所有权利.</p>
            </div>
        </div>
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const deleteButton = document.querySelector('.delete-image');
            const confirmDeleteButton = document.getElementById('confirmDelete');
            const deleteModal = new bootstrap.Modal(document.getElementById('deleteModal'));
            const imageId = deleteButton.getAttribute('data-image-id');

            deleteButton.addEventListener('click', function() {
                deleteModal.show();
            });

            confirmDeleteButton.addEventListener('click', function() {
                fetch(`/data/delete/${imageId}`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    }
                })
                .then(response => response.json())
                .then(data => {
                    if (data.success) {
                        window.location.href = "{{ url_for('data.my_data') }}";
                    } else {
                        alert('删除失败: ' + data.message);
                    }
                })
                .catch(error => {
                    console.error('删除出错:', error);
                    alert('操作失败，请重试');
                });
            });
        });
    </script>
</body>
</html> 